import os,zipfile,re

m2path = '/Users/zeshuoyin/.m2/repository'
invalidOnly = True

def main():
  for root,dirs, files in os.walk(m2path):
    for name in files:
      if re.search(r'jar$', name):
        fn = os.path.join(root, name)
        zf = zipfile.ZipFile(fn, mode='r')
        data = zf.testzip()
        if data:
          print 'Invalid Zip File : ', os.path.join(root, name)
          os.remove(fn)
        elif invalidOnly == False:
          print 'Valid Zip File : ', os.path.join(root, name)

if __name__ == "__main__":
  main()